#include "StomperLib/Controls/ToolWindow.h"

namespace StomperLib
{
namespace Controls
{
ToolWindow::ToolWindow( BaseLayout* base ) : Gwen::Controls::WindowControl( base )
{
  Model = base->Model;
  SetDeleteOnClose( false );
}

void ToolWindow::ParseProperties( Json::Value config )
{
  auto windowConfig = config["Editor Properties"]["Tool Windows"][this->GetName( )];

  this->SetWidth( windowConfig.get( "Width", 200 ).asUInt( ));
  this->SetHeight( windowConfig.get( "Height", 200 ).asUInt( ));
  this->SetPos(
    Gwen::Point(
      windowConfig.get( "X", 200 ).asUInt( ),
      windowConfig.get( "Y", 200 ).asUInt( )));
  if (!windowConfig.get( "IsToggeled", true ).asBool( ))
  {
    this->CloseButtonPressed( );
  }
}

void ToolWindow::SaveProperties( Json::Value& root )
{
  Json::Value data;

  data["Width"] = this->Width( );
  data["Height"] = this->Height( );
  data["X"] = this->X( );
  data["Y"] = this->Y( );
  data["IsToggeled"] = !this->Hidden( );

  root[this->GetName( )] = data;
}

}

}